<template>
    <div class="list_retrieval-territory">
        <header>
            <h3>{{title}}</h3>
            <div class="drop-down" @click = 'isTerritory = !isTerritory'>
                <i :class="['iconfont',isTerritory?'icon-shang':'icon-xiala']"></i>
            </div>
        </header>
        <ul>
            <li :key="item.key" v-for="item in formatData" :class="{'active':item.isHightlight}" @click="onSelect({item,myData})">
                <p>
                    {{item.value}}
                </p>
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    computed:{
        formatData(){
            if(this.isTerritory){
                return this.myData.slice(0,8)
            }else{
                return this.myData
            }
        }
    },
    data: function(){
        return {
            isTerritory: true,
            isExist: true
        }
    },
    props: {
        title: String,
        myData: Array,
    },
    methods: {
        onSelect(data){
            (data.myData).forEach(element => {
                element.isHightlight = false
            });
            this.isExist = !this.isExist
            data.item.isHightlight = !data.item.isHightlight
            this.$emit('onclick',{value:data.item.value,source:data.myData,id:data.item.id})
        }
    }
}
</script>

<style lang="scss" scoped>
    .list_retrieval-territory{

        box-sizing: border-box;
        box-shadow: 0 1px 0 0 #eee;
        padding: 20px 0;
        margin: 0 .3rem 0 .3rem;
        header{
            box-sizing: border-box;
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 28px;
            color: #aaa;
            margin-bottom: 15px;
            .drop-down{
                transform: rotate(180deg);
                transition-duration: .5s;
            }
        }
        ul{
            display: flex;
            align-items: center;
            align-content: space-between;
            flex-wrap: wrap;
            padding-bottom: 20px;
            box-sizing: border-box;
            li{
                box-sizing: border-box;
                font-size: 24px;
                margin-top: 20px;
                width:48%;
                height: 76px;
                text-align: center;
                border-radius: 0.1rem;
                background: #FFF;
                color: #666;
                line-height: 38px;
                display: flex;
                align-items: center;
                justify-content: center;
                &:nth-child(odd){
                  margin-right: 4%;
                }
                p{
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    line-break: 2;
                    -webkit-box-orient: vertical;
                    letter-spacing: 3px;
                }
                    
                &.active{
                    background: #7698f7;
                    color: #fff;
                }
            }
        }
    }
</style>

